package com.three.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.three.dao.AnnounceDao;
import com.three.dao.CrollcallDao;
import com.three.entity.Announce;
import com.three.entity.Crollcall;
import com.three.service.AnnounceService;
import com.three.service.CrollcallService;

@Service
public class AnnounceServiceImpl implements AnnounceService {

	@Autowired
	AnnounceDao announceDao;
	
	@Override
	public List<Announce> findAnnouncesByCid(Integer cid) {
		// TODO Auto-generated method stub
		return announceDao.findAnnouncesByCid(cid);
	}

	/**
	 *添加公告
	 *成功返回"success" 失败返回"failed"
	 */
	@Override
	public String addAnnounce(Announce ann) {
		int state = announceDao.addAnnounce(ann);
		String result = null;
		if (state>0) {
			int aid = announceDao.findLastInsertIdByCid(ann.getCid());
			result = aid + "";
		}else{
			result = "0";
		}
		return result;
	}

	@Override
	public String editAnnounce(Integer aid, String title, String content) {
		String result = null;
		int state = announceDao.updateAnnounce(aid, title, content);
		if (state>0) {
			result = "success";
		}else{
			result = "failed";
		}
		return result;
	}

	@Override
	public String deleteAnnounce(Integer aid) {
		int state = announceDao.deleteAnnouncesByAid(aid);
		String result = null;
		if (state>0) {
			result = "success";
		}else{
			result = "failed";
		}
		return result;
	}
	
	

}
